from django.shortcuts import render
from com.com_functions import load_class,load_class_with_args


# Create your views here.
# 加载页面函数
def load_page(request, c1, c2):
    if not c2:
        c2 = c1
    _c2 = c2.split("_")
    _c2 = [c.title() for c in _c2]
    get_class = load_class('com' + '.' + c1 + '.' + c2 + '_controller', "".join(_c2), request)
    if not get_class:
        return render(request, "404.html", {})
    return get_class.run()


def load_page_with_three_args(request, c1, c2, c3):
    _c2 = c2.split("_")
    _c2 = [c.title() for c in _c2]
    get_class = load_class_with_args('com' + '.' + c1 + '.' + c2 + '_controller', "".join(_c2), request, c3)
    if not get_class:
        return render(request, "404.html", {})
    return get_class.run()

def index(request):
    return load_page(request, "index", "index")
